document.getElementById('status').innerText = 'Hello world22!';

// JavaScript代码
// #www-home-right > div.www-home-silde > div.ContentBlock > div:nth-child(2) > div > span
document
  .getElementById("actionButton")
  .addEventListener("click", function () {
    console.log('click');
    // 在这里添加你的功能代码
    chrome.tabs.query(
      { active: true, currentWindow: true },
      function (tabs) {
        chrome.scripting.executeScript({
          target: { tabId: tabs[0].id },
          func: () => {
            // Your content script logic here
            console.log("Content script injected from popup!");
            let elems = document.querySelectorAll(
              "#www-home-right > div.www-home-silde > div.ContentBlock > div"
            );
            elems.forEach((it) => {
              it.style.background = "red";
            });
          },
        });
      }
    );
  });

document
  .getElementById("filterBtn")
  .addEventListener("click", function () {
    document.getElementById('status').innerText = `Hello world ${Math.random()}`;
    chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
      const tabId = tabs[0].id;
      chrome.tabs.sendMessage(tabId, {
        action: "changeFilterSwitch"
      });
    });
  });

document.onload = function () {
  chrome.storage.local.onChanged.addListener(function (changes, namespace) {
    const message = changes.messageForPopup?.newValue;
    if (message) {
      console.log("Received message from background script:", JSON.parse(message).data);
      localStorage.removeItem("messageForPopup"); // Remove processed message
      // Update popup UI or perform actions based on the data
      document.getElementById('status').innerText = JSON.parse(message).data;
    }
  });
}

